# -*- coding: utf-8 -*-

__authur__ = 'Yu XH'

import pandas as pd
# import time

# ==== 把excel文件转换成pickle文件 ====
# a = pd.read_excel('巡飞弹射击损伤分析.xlsx', sheet_name=1)
# a.to_pickle('cm_damage_tab.pkl')
# c = pd.read_pickle('cm_damage_tab.pkl')


def get_cm_damage(type=2, blood=3, keep=0, armor=0, terrain='开阔地', move_state=0, is_moving=0, stack=0):
    """计算巡飞弹的战损结果"""
    cm_damage_tab = pd.read_pickle('cm_damage_tab.pkl')
    if type == 2:  # 如果是车辆
        index = (cm_damage_tab['type'] == type)\
                & (cm_damage_tab['blood'] == blood)\
                & (cm_damage_tab['armor'] == armor)\
                & (cm_damage_tab['terrain'] == terrain)\
                & (cm_damage_tab['move_state'] == move_state)\
                & (cm_damage_tab['is_moving'] == is_moving)\
                & (cm_damage_tab['stack'] == stack)
    elif type == 1:  # 如果是人员
        index = (cm_damage_tab['type'] == type) & \
                (cm_damage_tab['blood'] == blood) & \
                (cm_damage_tab['keep'] == keep) & \
                (cm_damage_tab['terrain'] == terrain) & \
                (cm_damage_tab['move_state'] == move_state) & \
                (cm_damage_tab['is_moving'] == is_moving) & \
                (cm_damage_tab['stack'] == stack)
    if True in index.values:
        return cm_damage_tab[index].iat[0, -1]
    else:
        return None
